package com.aisi.backend.service.impl;

import com.aisi.backend.domain.entity.Account;
import com.aisi.backend.domain.entity.AccountDetails;
import com.aisi.backend.domain.vo.request.DetailsAccountSaveVo;
import com.aisi.backend.domain.vo.response.AccountDetailsVo;
import com.aisi.backend.mapper.AccountDetailsMapper;
import com.aisi.backend.mapper.AccountMapper;
import com.aisi.backend.service.AccountDetailsService;
import com.aisi.backend.utils.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: shenjianZ
 * @Date: 2024/5/10 下午5:32
 * @Description:
 */


public class AccountDetailsServiceImpl implements AccountDetailsService {

    @Override
    public AccountDetails findAccountDetailsById(Integer userId) {
        try (SqlSession session = MybatisUtil.getSqlSession(true)) {
            AccountDetailsMapper mapper = session.getMapper(AccountDetailsMapper.class);
            AccountDetails accountDetails = null;
            accountDetails = mapper.findAccountDetailsById(userId);
            return accountDetails;
        }
    }

    @Override
    public boolean saveAccountDetails(Integer userId, DetailsAccountSaveVo vo) {
        try (SqlSession session = MybatisUtil.getSqlSession(true)) {
            AccountDetailsMapper mapper = session.getMapper(AccountDetailsMapper.class);
            Map<String, Object> parameters = new HashMap<>();
            parameters.put("userId", userId);
            parameters.put("sex", vo.getSex());
            parameters.put("phone", vo.getPhone());
            parameters.put("qq", vo.getQq());
            parameters.put("wx", vo.getWx());
            parameters.put("description", vo.getDescription());
            Integer i = mapper.saveAccountDetails(parameters);
            return i > 0;
        }
    }
}
